package com.bw.lib_storage.mmkv

import com.bw.lib_storage.mmkv.utils.MMKVOwner
import com.bw.lib_storage.mmkv.utils.MMKVProperty
import com.tencent.mmkv.MMKV
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

object TimeMMKV : MMKVOwner {
    override val mmkv: MMKV
        get() = MMKV.mmkvWithID("time")

    var loginTime  by MMKVProperty(0L)
    var logoutTime by MMKVProperty(0L)

    fun getLastUpdateTimeFormatted(): String {
        return if (loginTime == 0L) {
            "从未更新"
        } else {
            val date = Date(loginTime)
            SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(date)
            val date1 = Date(logoutTime)
            SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(date1)
        }
    }


    fun updateLastUpdateTime() {
        loginTime = System.currentTimeMillis()
    }
}